package com.gonsin.ta.logic;


import com.gonsin.ta.logic.parse.TaExecutorService;
import com.gonsin.ta.logic.process.TaReady;
import com.gonsin.ta.logic.process.TaSignal;
import com.gonsin.ta.logic.spring.ComponentScanner;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@Configuration
@ComponentScan("com.gonsin.ta")
@EntityScan("com.gonsin.ta")
@EnableJpaRepositories
@MapperScan("com.gonsin.ta.**.mapper")
@EnableConfigurationProperties
@Slf4j
public class TA {

    static {
        ComponentScanner.putBean("log", log);
    }

    /**
     * 用于全局输出日志
     * @return
     */
    public static Logger log(){
        return log;
    }

    /**
     * 是否输出日志
     */
    public static boolean LOG = false;


    public static TaExecutorService __INSTANCE;

    /**
     * 准备执行流程
     */
    public static TaReady ready(String chainId){
        return new TaReady(__INSTANCE, chainId);
    }


    /**
     * 向流程实例发送信号
     */
    public static TaSignal signal(String instanceId, String signal) {
        return new TaSignal(__INSTANCE, instanceId, signal);
    }
}
